package com.example.myapplication.service;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import java.util.Random;

public class MyBindService extends Service {
    final static String TAG = "MyBindService";
    IBinder iBinder =null;
    Random mGenerator;
    public MyBindService() {
    }

    public class MyBinder extends Binder {
        MyBindService getService(){
            return MyBindService.this;
        }
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        Log.i(TAG, "onBind: ..................");
        return  iBinder;
    }

    @Override
    public void onCreate() {
        Log.i(TAG, "onCreate: ..................");
        mGenerator = new Random();
        iBinder = new MyBinder();
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        Log.i(TAG, "onDestroy: ..................");
        super.onDestroy();
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.i(TAG, "onUnbind: ..................");
        return super.onUnbind(intent);
    }

    @Override
    public void onRebind(Intent intent) {
        Log.i(TAG, "onRebind: ..................");
        super.onRebind(intent);
    }

    public int getRandomNumber(){
        return mGenerator.nextInt(100);
    };
}